import { request } from '@umijs/max';

/**
 * 获取用户列表
 * @param data
 */
export async function getPageUserListFun(data) {
  return request(`/sysUser/getPageUserList`, {
    method: 'post',
    data,
  });
}

/**
 * 文件上传
 * @param file
 */
export function fileUploadFun(file) {
  const data = new FormData();
  data.append('file', file);
  return request('/edu/main/upload', {
    method: 'post',
    data,
  });
}

// 添加新用户
export async function addUserFun(data) {
  return request('/sysUser/addUser', {
    method: 'post',
    data,
  });
}

// 根据ID获取用户信息
export async function getUserByIdFun(id) {
  return request(`/sysUser/getUserById?userId=${id}`, {
    method: 'get',
  });
}

// 删除用户
export async function deleteUserFun(id) {
  return request(`/sysUser/deleteUser?userId=${id}`, {
    method: 'delete',
  });
}

// 修改用户
export async function updateUserFun(data) {
  return request('/sysUser/updateUser', {
    method: 'put',
    data,
  });
}

// 查询角色列表
export async function getAllRoleFun(params) {
  return request('/sysRole/getAllRole', {
    method: 'get',
    params,
  });
}

// 根据ID查询角色信息
export async function getRoleByIdFun(id) {
  return request(`/sysRole/getRoleById?roleId=${id}`, {
    method: 'get',
  });
}

// 添加角色
export async function addRoleFun(data) {
  return request('/sysRole/addRole', {
    method: 'post',
    data,
  });
}

// 修改角色
export async function updateRoleFun(data) {
  return request('/sysRole/updateRole', {
    method: 'put',
    data,
  });
}

// 删除角色
export async function deleteRoleFun(id) {
  return request(`/sysRole/deleteRole?roleId=${id}`, {
    method: 'post',
  });
}

// 获取用户角色列表
export async function getUserRoleListFun(id) {
  return request(`/sysUserRole/getUserRoleList?userId=${id}`, {
    method: 'get',
  });
}

// 保存用户角色信息
export async function setUserRoleFun(data, userId) {
  return request(`/sysUserRole/setUserRole?userId=${userId}`, {
    method: 'post',
    data,
  });
}

// 保存角色菜单信息
export async function setRoleMenuFun(data) {
  return request(`/sysRoleMenu/addRoleMenu`, {
    method: 'post',
    data,
  });
}

// 根据角色ID查询菜单列表
export async function getCheckedKeysFun(roleId) {
  return request(`/sysRoleMenu/getCheckedKeys?roleId=${roleId}`, {
    method: 'get',
  });
}

// 根据角色ID查询菜单列表
export async function getRoleMenuFun(roleIds) {
  return request(`/sysRoleMenu/getRoleMenu`, {
    method: 'post',
    data: roleIds,
  });
}
